package tabletree;

import javax.swing.event.*;


import filesystem.*;

public class FileSystemTreeSelectionListener implements TreeSelectionListener 
{
	FileSystemAdapter m_filesystemadapter;
	
	public FileSystemTreeSelectionListener(FileSystemAdapter filesystemadapter) 
	{
		m_filesystemadapter = filesystemadapter;
	}

	@Override
	public void valueChanged(TreeSelectionEvent tse) 
	{
		if (tse.getNewLeadSelectionPath() == null) return; 
		
		
		FSElement fse = (FSElement)(tse.getPath().getLastPathComponent());
		if (fse instanceof Directory )
		{
			//Object tableData[][]
			m_filesystemadapter.setCurrent(fse);
			//update the table
			m_filesystemadapter.SetData();
			
			TableModelEvent e = new TableModelEvent(m_filesystemadapter);
			m_filesystemadapter.fireTableChanged(e);
			
		}
		
		/*
		 DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree
                               .getLastSelectedPathComponent();

               if (node == null)
                       return;

               Object nodeInfo = node.getUserObject();
               if (node.isLeaf()) // if element=File
               {  //adapter.setRoot(nodeInfo);
                       Object prevCurDir = adapter.getCurDir();// save cur dir
                       Object tableData[][];
                       tableData = adapter.getChildInfo(nodeInfo);// information of THE CHILD
                                                                       
                       constructTable(tableData);// build table
                       adapter.setCurDir(prevCurDir);// restore cur dir
                       TableModelEvent e = new TableModelEvent(jTable.getModel());
                       myTableModel.fireTableChanged(e);// inform listners of table data
                                                                                               // change
               }  
		 */

	}

}
